﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace WindowsFormsApplication1
{
    public partial class frmMain : Form
    {
        public static string[] fileList;
//        public string fileType;

        public frmMain()
        {
            InitializeComponent();
            this.pbxTomobile.AllowDrop = true;
        }

        //ToScreen1(): Shows all elements of Screen 1 and hides all others
        public int ToScreen1()
        {
            pbxToipod.Show();
            pbxTopsp.Show();
            pbxTozune.Show();
            pbxToyoutube.Show();
            pbxTomobile.Show();
            lblText.Hide();
            lbxConvert.Hide();
            btnAdd.Hide();
            btnRemove.Hide();
            btnStartOver.Hide();
            btnConvert.Hide();
            lblConverting.Hide();
            proBar.Hide();
            btnCancel.Hide();
            lblComplete.Hide();
            btnMainMenu.Hide();
            btnQuit.Hide();
            return 0;
        }

        //ToScreen2(): Shows all elements of Screen 2 and hides all others
        public int ToScreen2()
        {
            pbxToipod.Hide();
            pbxTopsp.Hide();
            pbxTozune.Hide();
            pbxToyoutube.Hide();
            pbxTomobile.Hide();
            lblText.Show();
            lbxConvert.Show();
            btnAdd.Show();
            btnRemove.Show();
            btnStartOver.Show();
            btnConvert.Show();
            lblConverting.Hide();
            proBar.Hide();
            btnCancel.Hide();
            lblComplete.Hide();
            btnMainMenu.Hide();
            btnQuit.Hide();
            return 0;
        }

        //ToScreen3(): Shows all elements of Screen 3 and hides all others
        public int ToScreen3()
        {
            pbxToipod.Hide();
            pbxTopsp.Hide();
            pbxTozune.Hide();
            pbxToyoutube.Hide();
            pbxTomobile.Hide();
            lblText.Hide();
            lbxConvert.Hide();
            btnAdd.Hide();
            btnRemove.Hide();
            btnStartOver.Hide();
            btnConvert.Hide();
            lblConverting.Show();
            proBar.Show();
            btnCancel.Show();
            lblComplete.Hide();
            btnMainMenu.Hide();
            btnQuit.Hide();
            return 0;
        }

        //ToScreen4(): Shows all elements of Screen 4 and hides all others
        public int ToScreen4()
        {
            pbxToipod.Hide();
            pbxTopsp.Hide();
            pbxTozune.Hide();
            pbxToyoutube.Hide();
            pbxTomobile.Hide();
            lblText.Hide();
            btnAdd.Hide();
            btnRemove.Hide();
            btnStartOver.Hide();
            btnConvert.Hide();
            lblConverting.Hide();
            proBar.Hide();
            btnCancel.Hide();
            lblComplete.Show();
            lbxConvert.Show();
            btnMainMenu.Show();
            btnQuit.Show();
            return 0;
        }

        public int ProcessFile()
        {
            //This will contain the code for creating the batch file used for the conversion process
            TextWriter bat = new StreamWriter("convert.bat");
            string directory = Directory.GetCurrentDirectory();
            MessageBox.Show(directory);
            string nav = "cd " + directory + "\\Resources\\";
            MessageBox.Show(nav);
            MessageBox.Show(frmMain.fileList[0]);
            string faac = "faac.exe -b 192 -o 1.aac " + frmMain.fileList[0];
            MessageBox.Show(faac);
            bat.WriteLine(faac);
            string x264 = "x264.exe --profile baseline --level 3 --vbv-bufsize 2500 --vbv-maxrate 2500 --qp 23 --keyint 250 --min-keyint 25 --trellis 0 --output " + sfdSave.FileName + " " + fileList[0];
            MessageBox.Show(x264);
            bat.WriteLine(x264);
            return 0;
        }

        private void pbxMainLogo_Click(object sender, EventArgs e)
        {
            ToScreen2();
        }

        //Reads file info from what was drag and dropped here
        //TO DO: Support multiple file drops
        private void pbxTomobile_DragDrop(object sender, DragEventArgs e)
        {
            string[] fileList = (string[])e.Data.GetData(DataFormats.FileDrop, false);
            MessageBox.Show(fileList[0]);
            string ext = Path.GetExtension(fileList[0]);
            //MessageBox.Show(ext);
            if ((ext == ".avi") | (ext == ".wmv") | (ext == ".mpg") | (ext == ".mpeg"))
            {
                sfdSave.Filter = "MPEG-4 (*.mp4)|*.mp4";
                sfdSave.DefaultExt = "mp4";
                sfdSave.Title = "What would you like to name the new file?";
                sfdSave.FileName = fileList[0];
                if (sfdSave.ShowDialog() == DialogResult.OK)
                {
                    ProcessFile();
                }
            }
            else
            {
                MessageBox.Show("Invalid File Type!  Only AVI, WMV, and MPEG are accepted.");
            }
        }

        //Shows copy effect while dragging
        private void pbxTomobile_DragEnter(object sender, DragEventArgs e)
        {
            e.Effect = DragDropEffects.Copy;
        }
    }
}
